package com.mcy.springbatch.job.nestjob;

import com.mcy.springbatch.job.BaseJobConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class ChildJob2DemoConfig extends BaseJobConfig {

    @Bean
    public Job childJobTwo(){
        return jobBuilderFactory.get("childJobTwo")
                .incrementer(new RunIdIncrementer())
                .start(childJob2Step())
                .build();
    }

    @Bean
    public Step childJob2Step(){
        return stepBuilderFactory.get("childJob2Step")
                .tasklet(new Tasklet() {
                    @Override
                    public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
                        log.info("ChildJob2-----childJob2Step......");
                        return RepeatStatus.FINISHED;
                    }
                })
                .build();
    }


}
